<template>
	<view class="warp" style="background-color: #FFFFFF;">
		<view class="home_top1"></view>
		<view class="info box-s1 box">
			<view class="tabbar">
				<tabBar @childFn="childFn" :tabTitle="tabTitle"></tabBar>
			</view>
			<view v-if="activename == 0">
				<view class="item flex mt30">
					<view class="acea-row1 row-middle">
						<text class="iconfont cmain">&#xe6a3;</text>
						<input type="text" placeholder="请输入您的账号" v-model="account"  required/>
					</view>
				</view>
				<view class="item flex mt30">
					<view class="acea-row1 row-middle">
						<text class="iconfont cmain">&#xe61d;</text>
						<input type="password" placeholder="请输入您的密码" v-model="password" required />
					</view>
				</view>

				<view class="logo_Speed mt30" @click="forget">
					<text>忘记密码</text>
				</view>
			</view>
			
			<!-- 验证码登录 -->
			<view v-if="activename == 1">
				<view class="item flex mt30">
					<view class="acea-row1 row-middle">
						<text class="iconfont cmain">&#xe6a3;</text>
						<input type="text" maxlength="11" placeholder="请输入您的手机号" v-model="phone" />
					</view>
				</view>
				<view class="item flex mt30">
					<view class="acea-row1 row-middle">
						<text class="iconfont cmain">&#xe613;</text>
						<input type="text" placeholder="请输入验证码" v-model="captcha" required />
					</view>
					<view class="code cmain" :disableds="disableds" @click="addlogin">
					  {{yzmtext}}
					</view>

				</view>
				<view class="cmain fs20 mt20" style="padding:0 0rpx 0 30rpx;">
					·订单信息和服务信息与手机号相关联，请慎重选择手机号登录
				</view>
				<view class="cmain fs20 mt20" style="padding:0 30rpx;">
					·登录即视为同意《力高商厨隐私政策》
				</view>
			</view>

			<view class="logon bmain" @click="sumbit">登&nbsp;&nbsp;&nbsp;&nbsp;录</view>
		</view>

	</view>
</template>

<script>
	import tabBar from '../../compontents/tab.vue'
	import {loginMobile,ordinaryLogin,verify_code,sendverify} from '../../api/api.js'
	export default {
		components: {
			tabBar
		},
		data() {
			return {
				yzmtext:"获取验证码",
				disableds:true,
				tabTitle: [{
					name: "密码登录"
				}, {
					name: "验证码登录"
				}],
				keyApi:"",
				check: "",
				phone:"",
				data1: "",
				activename: 0,
				account: "",
				password: "",
			}
		},
		onLoad() {
			 this.getAPICode()
		},
		methods: {
			getAPICode(){
			  verify_code().then((res)=>{
			    console.log(res)
			    this.keyApi = res.data.key
			  })
			},
			addlogin(){
				console.log('发送验证码',this.disableds)
			  if(this.disableds){
			    this.disableds=false
			    this.addCodes()
			  }else{
			    return
			  }
			},
			addCodes() {
			  let that = this
			  console.log('111111111')
			  if (!that.phone) {
				  this.disableds = true
				  uni.showToast({
				  	title: '请填写手机号!',
				  				icon:"none"
				  })
				  return
			  }
			  sendverify({
			    phone:that.phone,
			    key:that.keyApi
			  }).then((res) => {
			    console.log(res)
			      uni.showToast({
			      	title:res.msg,
			      				icon:"none"
			      })
			      let times = 60
			      let timer = setInterval(()=>{
			           times--;
			           that.yzmtext = times + "s"
			           if(times <=0 ){
			             that.disableds = true
			             that.yzmtext = '重新获取'
			             clearInterval(timer)
			           }
			        },1000)
			    
			  }).catch(res => {
			   uni.showToast({
			   	title:res.msg,
				icon:"none"
			   })
			  });
			},
			// 跳转页面
			childFn(e) {
				console.log(e)
				this.account = ''
				this.password = ''
				this.activename = e
			},
			// 登录
			sumbit(){
				if(this.activename == 0){  //普通登录
				if(!this.account || !this.password) {
					uni.showToast({
						title:"账号或密码为空!",
						icon:"none"
					})
					return
				}
					let data = {
						account:this.account,
						password:this.password,
					}
					ordinaryLogin(data).then(res=>{
						uni.showToast({
							title:res.msg,
										icon:"none"
						})
					})
				}
				else if(this.activename == 1){ //验证码登录
					let data = {
						phone:this.phone,
						captcha:this.captcha,
						// spread:this.spread
					}
					loginMobile(data).then(res=>{
						uni.showToast({
							title:res.msg,
										icon:"none"
						})
						console.log(res.data)
						if(res.status == 200){
							uni.setStorageSync('token',res.data.token)
							uni.navigateTo({
								url:'/pages/identityChoice/index'
							})
						}
					})
				}
				
				
				
			},
			// 忘记密码
			forget(){
				uni.navigateTo({
					url:'/pages/login/forget'
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.info {
		width: 90%;
		left: 50%;
		top: 60rpx;
		position: absolute;
		border-radius: 10rpx;
		transform: translateX(-50%);
		height: 650rpx;
		opacity: 1;
		background-color: #FFFFFF;

		// display: flex;
		// justify-content: center;
		// align-items: center;
		.tabbar {
			text-align: center;
			height: 110rpx;
			line-height: 110rpx;
			border-bottom: 1rpx solid #E0EDFF;
		}
	}

	.box {
		width: 600rpx;
		height: 750rpx;
		border-radius: 20rpx;
		position: absolute;
		// top: 330rpx;
		left: 50%;
		transform: translate(-50%);
		background-color: #fff;

		.acea-row {
			margin-top: 150rpx;
			width: 550rpx;
			margin-left: 25rpx;
			padding: 20rpx;
			border-bottom: 2rpx solid #F5F5F5;

			image {
				margin-left: 50rpx;
				width: 50rpx;
				height: 50rpx;
			}

			input {
				margin-left: 40rpx;
			}
		}

		.acea-row1 {
			width: 550rpx;
			margin-left: 25rpx;
			padding: 20rpx;
			border-bottom: 2rpx solid #F5F5F5;

			image {
				margin-left: 50rpx;
				width: 50rpx;
				height: 50rpx;
			}

			input {
				display: inline-block;
				margin-left: 40rpx;
			}
		}

		.logo_Pwd {
			margin-left: 25rpx;
			margin-top: 25rpx;
			color: #ccc;
		}

		.logo_Speed {
			width: 200rpx;
			margin-top: 40rpx;
			margin-left: 450rpx;
			color: #ccc;
		}

		.logon {
			margin-top: 50rpx;
			border-radius: 80rpx;
			width: 550rpx;
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
			color: #fff;
			font-size: 34rpx;
			// font-weight: bold;
			margin-left: 25rpx;
			// background-color: #ff7c32;
		}

		.ennoll {
			margin-top: 30rpx;
			border-radius: 80rpx;
			width: 550rpx;
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
			color: #fff;
			font-size: 34rpx;
			font-weight: bold;
			margin-left: 25rpx;
			background-color: #ccc9cd;
		}
	}
	.code{
		width: 150rpx;
		font-size: 20rpx;
	}
</style>
